{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Keep Multiplying Found Values by Two"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #hash-table #sorting #simulation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #哈希表 #排序 #模拟"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: findFinalValue"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #将找到的值乘以 2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个整数数组 <code>nums</code> ，另给你一个整数 <code>original</code> ，这是需要在 <code>nums</code> 中搜索的第一个数字。</p>\n",
    "\n",
    "<p>接下来，你需要按下述步骤操作：</p>\n",
    "\n",
    "<ol>\n",
    "\t<li>如果在 <code>nums</code> 中找到 <code>original</code> ，将 <code>original</code>&nbsp;<strong>乘以</strong> 2 ，得到新 <code>original</code>（即，令 <code>original = 2 * original</code>）。</li>\n",
    "\t<li>否则，停止这一过程。</li>\n",
    "\t<li>只要能在数组中找到新 <code>original</code> ，就对新 <code>original</code> 继续 <strong>重复</strong> 这一过程<strong>。</strong></li>\n",
    "</ol>\n",
    "\n",
    "<p>返回<em> </em><code>original</code> 的 <strong>最终</strong> 值。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>nums = [5,3,6,1,12], original = 3\n",
    "<strong>输出：</strong>24\n",
    "<strong>解释：</strong> \n",
    "- 3 能在 nums 中找到。3 * 2 = 6 。\n",
    "- 6 能在 nums 中找到。6 * 2 = 12 。\n",
    "- 12 能在 nums 中找到。12 * 2 = 24 。\n",
    "- 24 不能在 nums 中找到。因此，返回 24 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>nums = [2,7,9], original = 4\n",
    "<strong>输出：</strong>4\n",
    "<strong>解释：</strong>\n",
    "- 4 不能在 nums 中找到。因此，返回 4 。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= nums.length &lt;= 1000</code></li>\n",
    "\t<li><code>1 &lt;= nums[i], original &lt;= 1000</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [keep-multiplying-found-values-by-two](https://leetcode.cn/problems/keep-multiplying-found-values-by-two/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [keep-multiplying-found-values-by-two](https://leetcode.cn/problems/keep-multiplying-found-values-by-two/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[5,3,6,1,12]\\n3', '[2,7,9]\\n4']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        while original in nums:\n",
    "            original *= 2\n",
    "        return original\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        self.ind = 0\n",
    "        if original not in nums:\n",
    "            return original\n",
    "\n",
    "        self.ind = nums.index(original)\n",
    "\n",
    "        def search_ind():\n",
    "            try:\n",
    "                self.ind = nums.index(nums[self.ind] * 2)\n",
    "            except ValueError:\n",
    "                return\n",
    "            search_ind()\n",
    "\n",
    "        search_ind()\n",
    "        return nums[self.ind] * 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        while original in nums:\n",
    "            nums.remove(original)\n",
    "            original*=2\n",
    "        return original\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        i=0\n",
    "        while i<len(nums):\n",
    "            if original==nums[i]:\n",
    "                original=original*2\n",
    "                i=-1\n",
    "            i+=1\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        while original in nums:original<<=1\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        t=original\n",
    "        while True:\n",
    "            if t not in nums:\n",
    "                return t\n",
    "            if t*2 in nums:\n",
    "                t=t*2\n",
    "            else:\n",
    "                return t*2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        nums.sort()\n",
    "        def findall(start,end):\n",
    "            if start>end:\n",
    "                return -1\n",
    "            pos=(end-start)//2+start\n",
    "            if nums[pos]==original:\n",
    "                return pos\n",
    "            elif original>nums[pos]:\n",
    "                return findall(pos+1,end)\n",
    "            else:\n",
    "                return findall(start,pos-1)\n",
    "        start=0\n",
    "        end=len(nums)-1\n",
    "        pos=findall(start,end)\n",
    "        while pos!=-1:\n",
    "            original=original*2\n",
    "            pos=findall(pos,end)\n",
    "        return original\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        while original in nums:\n",
    "            original*=2\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        while original in nums:\n",
    "            original <<= 1\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        while original in nums:\n",
    "            original *= 2\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        if original not in nums:\n",
    "            return original\n",
    "        return self.findFinalValue(nums, original * 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        nums.sort()\n",
    "        start = 0\n",
    "        while True:\n",
    "            flag = False\n",
    "            for i in range(start,len(nums)):\n",
    "                if nums[i] == original:\n",
    "\n",
    "                    flag = True\n",
    "                    original *= 2\n",
    "                    start = i\n",
    "                    break\n",
    "            if not flag:\n",
    "                break\n",
    "        return original\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        while original in nums:\n",
    "            original *= 2\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        num = original\n",
    "        nums_set = set(nums)\n",
    "        while num in nums_set:\n",
    "            num *= 2\n",
    "        return num"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        while original in nums:\n",
    "            original *= 2\n",
    "        return original "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        nums = set(nums)\n",
    "        while original in nums:\n",
    "            original = original*2\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        tmp=set(nums)\n",
    "        while True:\n",
    "            if original in tmp:\n",
    "                tmp.remove(original)\n",
    "                original*=2\n",
    "            else:\n",
    "                return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        while True:\n",
    "            if original in nums:\n",
    "                original = original * 2\n",
    "            else:break\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        m = 0\n",
    "        for x in nums:\n",
    "            if x % original != 0:\n",
    "                continue\n",
    "            q = x // original\n",
    "            if q & (q - 1) == 0:\n",
    "                m |= q\n",
    "        m = ~m\n",
    "        return (m & -m) * original\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        while True:\n",
    "            try:\n",
    "                nums[nums.index(original)] = original\n",
    "                original = original * 2\n",
    "            except:\n",
    "                return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        nums.sort()\n",
    "        for num in nums:\n",
    "            if num == original:\n",
    "                original *= 2\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    tem = 0\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        if original not in nums:\n",
    "            self.tem = original\n",
    "        else:\n",
    "            self.findFinalValue(nums,original*2)\n",
    "        return self.tem"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        while original in nums:\n",
    "            original=2*original\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        '''\n",
    "        用位运算的思路优化：用一个二进制数mask记录nums中含有哪些original的2的幂次倍数，然后找到mask最低位的0，对应mask取反后最低位的1。\n",
    "        这可以通过先对mask取反，再对其求lowbit实现。找到的该最低位的1即为可以达到的最大的2的幂次倍数。\n",
    "        '''\n",
    "        mask = 0\n",
    "        for num in nums:\n",
    "            if num % original == 0:\n",
    "                x = int(num / original)\n",
    "                if (x & (x - 1)) == 0:  # x 是 2 的幂次\n",
    "                    mask |= x           # 记录所有 2 的幂次\n",
    "        mask = ~mask                # 按位取反\n",
    "        return (mask & -mask) * original         # lowbit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        val = original\n",
    "        while original in nums:\n",
    "            val = original * 2\n",
    "            original = val\n",
    "        return val\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        while original in nums:\n",
    "            original*=2\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        nums = set(nums)\n",
    "        while original in nums:\n",
    "            original <<= 1\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        dic = set(nums)\n",
    "        while original in dic:\n",
    "            original *= 2\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        while original in nums:\n",
    "            original *= 2\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        a = True\n",
    "        while a == True:\n",
    "            if original in nums:\n",
    "                original = original * 2\n",
    "            else:\n",
    "                a = False\n",
    "        return original\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        while original in nums:\n",
    "            original *= 2\n",
    "\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        while original in nums:\n",
    "            original *= 2\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        while original in nums:original*=2\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        while original in set(nums):\n",
    "            original *= 2\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        if original not in nums:\n",
    "            return original\n",
    "        while original in nums:\n",
    "            original = original*2\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "'''\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        length = len(nums)\n",
    "        for i in range(length):\n",
    "            if original in nums:\n",
    "                original *= 2\n",
    "        return original \n",
    "'''\n",
    "\n",
    "class Solution:\n",
    "  def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "      while original in set(nums):\n",
    "          original *= 2\n",
    "      return original\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        while original in nums:\n",
    "            original *= 2\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        s=set(nums)\n",
    "        while original in s:\n",
    "            original=original*2\n",
    "        return original\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        while original in nums:\n",
    "            original*=2\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        set1 = set(nums)\n",
    "        while original in set1:\n",
    "            original = original * 2\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        while original in nums:\n",
    "            original = original*2\n",
    "        return original "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        while original in nums:\n",
    "            original *= 2\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: list[int], original: int) -> int:\n",
    "        if original not in nums:\n",
    "            return original\n",
    "        else:\n",
    "            return self.findFinalValue(nums, original * 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        length = len(nums)\n",
    "        for i in range(length):\n",
    "            if original in nums:\n",
    "                original *= 2\n",
    "        return original "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        nums.sort()\n",
    "        for i in range(len(nums)):\n",
    "            if nums[i] == original:         #找到了original\n",
    "                original *= 2\n",
    "            elif nums[i] > original:        #找不到original\n",
    "                break\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        cnt = set(nums)\n",
    "        while original in cnt:\n",
    "            original *= 2\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        nums.sort()\n",
    "        for n in nums:\n",
    "            if n == original:\n",
    "                original *= 2\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        # nums = [5,3,6,1,12], original = 3\n",
    "        nums = set(nums)\n",
    "        while original in nums:\n",
    "            original *= 2\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        while original in nums:\n",
    "            original *= 2\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        nums.sort()\n",
    "        for num in nums:\n",
    "            if num == original:\n",
    "                original *= 2\n",
    "        return original\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        s = set(nums)\n",
    "        while original in s:\n",
    "            original *= 2\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        while nums.count(original) != 0:\n",
    "            original *= 2\n",
    "        return original\n",
    "     \n",
    "\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        nums = set(nums)\n",
    "        while original in nums:\n",
    "            original *= 2\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        li = list()\n",
    "        i = original\n",
    "        while i <= 1000:\n",
    "            li.append(i)\n",
    "            i *= 2\n",
    "        dic = dict(zip(li, [False for _ in range(len(li))]))\n",
    "        for num in nums:\n",
    "            if num in dic.keys():\n",
    "                dic[num] = True\n",
    "        ans = original / 2\n",
    "        for x in sorted(dic):\n",
    "            if not dic[x]:\n",
    "                break\n",
    "            ans = x\n",
    "        return int(ans * 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        while original in nums:original<<=1\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        while original in nums:\n",
    "            original*=2\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        while original in nums:\n",
    "            original*=2\n",
    "        return original\n",
    "    \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        # if original not in nums:\n",
    "        #     return original\n",
    "        while original in nums:\n",
    "            original *=2\n",
    "\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        s = set(nums)\n",
    "        while original in s:\n",
    "            original = 2 * original\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        if original not in nums :\n",
    "            return original\n",
    "        nums.append(original)\n",
    "        while(original in nums):\n",
    "            original=2*original\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        while original in nums:\n",
    "            original *= 2\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        nums.sort()\n",
    "        for i in range(len(nums)):\n",
    "            if nums[i] == original:\n",
    "                original = 2 * original\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        nums = set(nums)\n",
    "        while original in nums:\n",
    "            original *= 2\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        nums.sort()\n",
    "        for num in nums:\n",
    "            if num == original:\n",
    "                original *= 2\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        s=set(nums)\n",
    "        while original in s:\n",
    "            original*=2\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        while original in nums:\n",
    "            original *= 2\n",
    "        return original"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        while True:\n",
    "            try:\n",
    "                index = nums.index(original)\n",
    "                nums.remove(original)\n",
    "                original *= 2\n",
    "            except:\n",
    "                break\n",
    "        return original\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        nums.sort()\n",
    "        for num in nums:\n",
    "            if num == original:\n",
    "                original *= 2\n",
    "        return original\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def findFinalValue(self, nums: List[int], original: int) -> int:\n",
    "        nums = set(nums)\n",
    "        while original in nums:\n",
    "            original *= 2\n",
    "        return original"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
